import time
from random import randint
 
def bubble(array):
    N = len(array)
    for i in range(N-1):
        for j in range(N-i-1):
            if array[j] > array[j+1]:
                buff = array[j]
                array[j] = array[j+1]
                array[j+1] = buff

def readvalues(filename):
    textvals = ""
    with open(filename) as f:
        textvals = f.read()
    return [int(i) for i in textvals.split("\n")]

def execute(arr):
    starttime = time.time()
    bubble(arr)
    endtime = time.time()
    totaltime = endtime - starttime
    #print(arr)
    #print(totaltime, "seconds")
    return totaltime

expectedresult = readvalues("m1_sorted.txt")

m1name = "m1_sorted.txt"
m2name = "m2_reverse.txt"
m3name = "m3_shuffle.txt"

arr_m1 = readvalues(m1name)
arr_m2 = readvalues(m2name)
arr_m3 = readvalues(m3name)

m1time = execute(arr_m1)
m2time = execute(arr_m2)
m3time = execute(arr_m3)

print(m1name, int(m1time * 1000), "milliseconds")
print(m2name, int(m2time * 1000), "milliseconds")
print(m3name, int(m3time * 1000), "milliseconds")